package route

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"svvenus/util/utgin"
	"svvenus/vpub/worker"
)
// HttpRegister 路由注册
// @return *gin.Engine
func HttpRegister() *gin.Engine {
	rt := gin.Default()

	//rt.Use(middleware.SafetyVerification())

	// 初始化数据接口
	rt.POST("/init", ServerInit)
	// 重载配置文件
	rt.POST("/conf", ServerConf)

	// gm指令
	rt.POST("/gmcmd", GmCmd)

	//v1 := rt.Group("/v1")
	//{
	//	// 渠道
	//	v1.POST("/channel/add", controller.ChannelAdd) // 渠道新增
	//}

	return rt
}

// ServerInit 初始化数据接口
func ServerInit(c *gin.Context) {
	ug := utgin.Gin{Ctx: c}
	ug.OkSuccess(nil, "Ok!")
	return
}

// ServerConf 重载配置文件
func ServerConf(c *gin.Context) {
	ug := utgin.Gin{Ctx: c}

	worker.CmdlineWorkerAddCmd("conf")

	ug.OkSuccess(nil, "重新读取配置文件成功！")
	return
}

// ServerDump 自调用打印
func ServerDump(c *gin.Context) {
	fmt.Println("ServerDump")
	var req interface{}
	_ = c.ShouldBindBodyWith(&req, binding.JSON)
	fmt.Println(req)
}

type ModGmCmd struct {
	Cmd string `json:"cmd"`
}
// GmCmd GM指令
// @param c
func GmCmd(c *gin.Context) {
	var req ModGmCmd
	_ = c.ShouldBindBodyWith(&req, binding.JSON)
	worker.CmdlineWorkerAddCmd(req.Cmd)
}
